package cn.kai.ums.controller;

import cn.kai.ums.mapper.UmsClassromeMapper;
import cn.kai.ums.model.UmsClassrome;
import cn.kai.ums.service.UmsClassromeService;
import cn.kai.ums.tools.JsonData;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("ums/v1/classroom")
@Api(tags = "教室空控制类")
public class ClassRoomController {

    @Autowired
    private UmsClassromeService umsClassromeService;

    @Autowired
    private UmsClassromeMapper umsClassromeMapper;

    @ApiOperation("根据教学楼编号和教室名称进行模糊查询")
    @GetMapping
    public JsonData getClassRome(@RequestParam (defaultValue = "1",required = false) Integer pageNum
            ,@RequestParam(defaultValue = "5",required = false) Integer pageSize
            ,@RequestParam(defaultValue = "",value = "likeclassrome",required = false) String likeclassrome){

        Page<UmsClassrome> classromePage = umsClassromeMapper.selectPage(new Page<>(pageNum,pageSize)
                , Wrappers.<UmsClassrome>lambdaQuery()
                        .like(UmsClassrome::getClassromeBuildingNo,likeclassrome)
                        .or()
                        .like(UmsClassrome::getClassromeName,likeclassrome));
        return JsonData.buildSuccess(classromePage);
    }


    @PostMapping
    public JsonData saveClassRome(@RequestBody UmsClassrome umsClassrome){
        return JsonData.buildSuccess(umsClassromeService.save(umsClassrome));
    }

    @PutMapping
    public JsonData updateClassRome(@RequestBody UmsClassrome umsClassrome){
        return JsonData.buildSuccess(umsClassromeService.updateById(umsClassrome));
    }

    @DeleteMapping
    public JsonData delClassRome(@RequestParam Integer crid){
        return JsonData.buildSuccess(umsClassromeService.removeById(crid));
    }

    @PostMapping("/delBatchClassRome")
    public JsonData delBatchClassRome(@RequestBody List<Integer> crids){
        return JsonData.buildSuccess(umsClassromeService.removeByIds(crids));
    }
}
